AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')

function ENT:SpawnFunction( ply, tr )
	if ( !tr.Hit ) then return end
	local SpawnPos = tr.HitPos + tr.HitNormal * 16
	local ent = ents.Create("sent_spaceanon_wormhole_trail")
	ent:SetPos( SpawnPos )
	ent:Spawn()
	ent:Activate()
	return ent
end

function ENT:Initialize()
	self.Entity:SetModel("models/props/cs_italy/orange.mdl")
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetColor(0,0,0,0)
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
	self.Entity:SetSolid(SOLID_VPHYSICS)
	local phys = self.Entity:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
		phys:EnableGravity(false)
	end
	self.ThrustOffset 	= Vector(0, 0, self.Entity:OBBMaxs().z)
	self.ForceAngle		= self.ThrustOffset:GetNormalized()*-1
	self.Force = 250
	self.Entity:StartMotionController()
	self.trail = util.SpriteTrail(self.Entity,0, Color(255,0,255,255),false, 5, 0, 3, 1, "trails/laser.vmt")
	self.Entity:SetCollisionGroup(COLLISION_GROUP_NONE)
	self:VecSelect()
end

function ENT:VecSelect()
	if not self.Entity then return end
	self.Vec = VectorRand()
	timer.Simple(3,self.VecSelect, self)
end

function ENT:PhysicsSimulate(phys, deltatime)
	local ForceAngle = self.ForceAngle
	local ForceLinear = self.Vec*self.Force
	return ForceAngle, ForceLinear, SIM_LOCAL_ACCELERATION
end
